package cn.micro.system.manage.service.impl;

import cn.micro.system.manage.entity.SysDimPosition;
import cn.micro.system.manage.entity.dto.SysDimPositionSearch;
import cn.micro.system.manage.mapper.SysDimPositionMapper;
import cn.micro.system.manage.service.SysDimPositionService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.function.Consumer;

/**
 * <p>
 * 岗位信息表 服务实现类
 * </p>
 *
 * @author wr
 * @since 2023-12-25
 */
@Service
public class SysDimPositionServiceImpl extends ServiceImpl<SysDimPositionMapper, SysDimPosition> implements SysDimPositionService {

    @Override
    public List<SysDimPosition> getByCodeOrName(SysDimPosition sysDimPosition) {
        LambdaQueryWrapper<SysDimPosition> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.and(sysDimPositionLambdaQueryWrapper -> sysDimPositionLambdaQueryWrapper.eq(StringUtils.isNotBlank(sysDimPosition.getCode()), SysDimPosition::getCode, sysDimPosition.getCode())
                .or()
                .eq(StringUtils.isNotBlank(sysDimPosition.getName()), SysDimPosition::getName, sysDimPosition.getName())).ne(StringUtils.isNotBlank(sysDimPosition.getId()), SysDimPosition::getId, sysDimPosition.getId());
        return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    public List<SysDimPosition> listByPage(int page, int size, SysDimPositionSearch search) {
        PageHelper.startPage(page, size);
        return this.baseMapper.queryByPage(search);
    }

    @Override
    public SysDimPosition getDetail(Long id) {
        return this.baseMapper.queryById(id);
    }
}
